import Vue from 'vue'
import VueRouter from 'vue-router'
import UserList from "../views/user/UserList";
import Login from "../views/Login";


Vue.use(VueRouter)

const routes = [
  {path: '/userList', component: UserList},
  {path: '/login', component: Login}

]



const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {
  if(to.path=='/login'){
    return next();
  }

  let user = sessionStorage.getItem("user");
  if(user){
    return next();
  }

  return next('/login');
})

export default router
